<!DOCTYPE html>
<html lang="en">
	<head>
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
		<meta charset="utf-8" />
		<title>驴妈妈流立方</title>
		<meta name="description" content="overview &amp; stats" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />
		<!-- bootstrap & fontawesome -->
		<link rel="stylesheet" href="${rc.contextPath}/assets/css/bootstrap.min.css" />
		<link rel="stylesheet" href="${rc.contextPath}/assets/font-awesome/4.5.0/css/font-awesome.min.css" />
		<!-- page specific plugin styles -->
		<link rel="stylesheet" href="${rc.contextPath}/assets/css/daterangepicker.min.css" />
		<link rel="stylesheet" href="${rc.contextPath}/assets/css/jquery.gritter.min.css" />
		<!-- text fonts -->
		<link rel="stylesheet" href="${rc.contextPath}/assets/css/fonts.googleapis.com.css" />
		<!-- ace styles -->
		<link rel="stylesheet" href="${rc.contextPath}/assets/css/ace.min.css" class="ace-main-stylesheet" id="main-ace-style" />
		<link rel="stylesheet" href="${rc.contextPath}/assets/css/ace-skins.min.css" />
		<link rel="stylesheet" href="${rc.contextPath}/assets/css/ace-rtl.min.css" />
		<!-- ace settings handler -->
		<script src="${rc.contextPath}/assets/js/ace-extra.min.js"></script>
		<link rel="stylesheet" href="${rc.contextPath}/assets/css/bsie-paginator.css" />
		<style>
			tr.detail-row {
				display: none
			}
			tr.detail-row.open {
				display: block;
				display: table-row
			}
		</style>
	</head>

	<body class="skin-2" style="background-color: #FFF;">
		<div class="page-content">
			<!-- <div class="page-header">
				<h1>
					统计code管理
					<small>
						<i class="ace-icon fa fa-angle-double-right"></i>
						code列表
					</small>
				</h1>
			</div> -->
			<div class="row">
				<div class="col-sm-12">
					<div class="row">
						<div class="col-xs-12">
							<div class="clearfix">
								<div class="pull-left tableTools-container">
									<button class="btn btn-xs btn-primary" onclick="skip('${rc.contextPath}/statisticCode/new')"><i class="ace-icon fa fa-pencil-square-o align-top bigger-125"></i>新增</button>
								</div>
							</div>
							<div class="tab-pane in active" id="codeList">
								<div id="dynamic-table_wrapper" class="dataTables_wrapper form-inline no-footer">
									<div class="row">
										<form class="form-inline" id="searchForm" method="post" action="${rc.contextPath}/statisticCode/list">
											<div class="col-xs-2">
												<div class="dataTables_length">
													<label>父级名称
														<input type="text" class="form-control" name="parentName" value="${statisticCodesConditionVO.parentName}" placeholder="模糊查询父级名称">
													</label>
												</div>
											</div>
											<div class="col-xs-2">
												<div class="dataTables_length">
													<label>中文名称
														<input type="text" class="form-control" name="name" value="${statisticCodesConditionVO.name}" placeholder="模糊查询中文名称">
													</label>
												</div>
											</div>
											<div class="col-xs-2">
												<div class="dataTables_length">
													<label>名称拼音
														<input type="text" class="form-control" name="enName" value="${statisticCodesConditionVO.enName}" placeholder="模糊查询名称拼音">
													</label>
												</div>
											</div>
											<div class="col-xs-2">
												<div class="dataTables_length">
													<label>code码
														<input type="text" class="form-control" name="code" value="${statisticCodesConditionVO.code}" placeholder="模糊查询code码">
													</label>
												</div>
											</div>
											<div class="col-xs-3 col-sm-3">
												<div class="dataTables_length">
													<button type="submit" class="btn btn-pink btn-sm" id="search">
														<span class="ace-icon fa fa-search icon-on-right bigger-110"></span>
														查询
													</button>
												</div>
											</div>
										</form>
									</div>
									<table id="dynamic-table" class="table table-striped table-bordered table-hover dataTable no-footer" role="grid" aria-describedby="dynamic-table_info">
										<thead>
											<tr>
												<th>No.</th>
												<th>父级名称</th>
												<th>中文名称</th>
												<th>名称拼音</th>
												<th>code码</th>
												<th>添加子级</th>
												<th>code码类型</th>
												<th>类型级别</th>
												<th>操作</th>
											</tr>
										</thead>
										<tbody>
											<#if statisticCodes?? && statisticCodes?size&gt;0>
												<#list statisticCodes as statisticCode>
												<tr class="">
													<td>${statisticCode_index + 1}</td>
													<td>${statisticCode.parent!}</td>
													<td>${statisticCode.name!}</td>
													<td>${statisticCode.enName!}</td>
													<td><#if statisticCode.parentId?? && statisticCode.parentId == 434>
														${statisticCode.code!}&nbsp;&nbsp;&nbsp;<i class="normal-icon ace-icon fa fa-eye green bigger-130" onclick="showimage('${rc.contextPath}/assets/images/pit.png')"></i>

													<#else>${statisticCode.code!}</#if></td>
													<td><#if statisticCode.isAdd == 1>允许<#else>不允许</#if></td>
													<td>${statisticCode.codeType!}</td>
													<td>${statisticCode.codeTypeLevel!}</td>
													<td>
														<a class="btn btn-minier btn-primary" onclick="updateCode(this);" value="${statisticCode.id!}" role="button">编辑</a>
														<!-- <a class="btn btn-minier btn-danger" href="${rc.contextPath}/menu/delete?id=${menu.id!}" role="button">删除</a> -->
														<!-- <#if menu.delFlag&gt;0>
															<a class="btn btn-minier btn-primary" href="${rc.contextPath}/menu/delFlag?id=${menu.id!}&delFlag=0" role="button">启用</a>
														<#else>
															<a class="btn btn-minier btn-primary" href="${rc.contextPath}/menu/delFlag?id=${menu.id!}&delFlag=1" role="button">停用</a>
														</#if> -->
													</td>
												</tr>
											</#list>
											<#else>
												<tr>
													<td colspan="12">
														<div class="alert alert-danger" style="margin-bottom: 0px;" role="alert">没有记录!</div>
													</td>
												</tr>
											</#if>
										</tbody>
									</table>
									<#include "paginator.html">
								</div>
							</div>
						</div>
					</div>
					<div class="row">
						<div class="col-xs-12">
							<button class="btn btn-info" data-toggle="modal" type="button" style="display:none;" id="update"
								   data-target="#myModal" <#if statisticCode?? && statisticCode.id??>disabled='true' readOnly='true'</#if>>
							</button>
							<form id="updateCode" class="form-horizontal" role="form">
							<div class="modal fade" id="myModal" tabindex="-1" role="dialog" 
								   aria-labelledby="myModalLabel" aria-hidden="true">
								   <div class="modal-dialog">
								      <div class="modal-content">
								         <div class="modal-header">
								            <button type="button" class="close" 
								               data-dismiss="modal" aria-hidden="true">
								                  &times;
								            </button>
								            <h4 class="modal-title" id="myModalLabel">
								               	编辑code
								            </h4>
								         </div>
							         <div class="modal-body">
										<input type="hidden" id="id" name="id" value="${statisticCode.id}">
										<div class="form-group">
											<label class="col-sm-4 control-label no-padding-right" for="form-field-1"> <strong class="text-danger">*</strong>父级code码 </label>
											<div class="col-sm-8">
												<input type="hidden" id="parent" name="parent" value="${statisticCode.parent.id!}">
												<input type="text" id="parentText" name="parentText" placeholder="请选择父级code码" value="${statisticCode.parent!}" class="col-xs-12 col-sm-6" disabled='true' readOnly='true'>
											</div>
										</div>
										<div class="space-4"></div>
										<div class="form-group">
											<label class="col-sm-4 control-label no-padding-right" for="form-field-1"> <strong class="text-danger">*</strong>中文名称 </label>
											<div class="col-sm-8">
												<input type="text" id="name" name="name" placeholder="请输入名称" value="${statisticCode.name!}" class="col-xs-12 col-sm-6" >
												<input type="hidden" id="nameBak" name="nameBak" value="">
											</div>
										</div>
										<div class="space-4"></div>
										<div class="form-group">
											<label class="col-sm-4 control-label no-padding-right" for="form-field-1"> <strong class="text-danger">*</strong>名称拼音 </label>
											<div class="col-sm-8">
												<input type="text" id="enName" name="enName" placeholder="请输入名称拼音" value="${statisticCode.enName!}" class="col-xs-12 col-sm-6" >
											</div>
										</div>
										<div class="space-4"></div>
										<div class="form-group">
											<label class="col-sm-4 control-label no-padding-right" for="form-field-1"> <strong class="text-danger">*</strong>code码 </label>
											<div class="col-sm-8">
												<input type="text" id="code" name="code"  value="${statisticCode.code!}" class="col-xs-12 col-sm-6" disabled='true' readOnly='true'>
											</div>
										</div>
										<div class="space-4"></div>
										<div class="form-group">
											<label class="col-sm-4 control-label no-padding-right" for="form-field-1"> <strong class="text-danger">*</strong>添加子级 </label>
											<div class="col-sm-3">
												<select class="form-control" name="isAdd" id="isAdd">
													<option value="1">允许</option>
													<option value="0">不允许</option>
												</select>
											</div>
										</div>
							         </div>
							         <div class="modal-footer">
							            <button type="button" class="btn btn-default"
							               data-dismiss="modal">关闭
							            </button>
							            <button id="save" type="button" class="btn btn-primary" >
							              	 提交
							            </button>
							         </div>
							      </div><!-- /.modal-content -->
								</div><!-- /.modal -->
							</div>
							</form>
						</div>
					</div>
					<div id="ShowImage_Form" class="modal">
						<div class="modal-header">
							<button data-dismiss="modal" class="close" type="button"></button>
						</div>
						<div class="modal-body">
							<div id="img_show">
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
		<script src="${rc.contextPath}/assets/js/jquery-2.1.4.min.js"></script>
		<script type="text/javascript">
			if('ontouchstart' in document.documentElement) document.write("<script src='${rc.contextPath}/assets/js/jquery.mobile.custom.min.js'>"+"<"+"/script>");
		</script>
		<script src="${rc.contextPath}/assets/js/bootstrap.min.js"></script>
		<script src="${rc.contextPath}/assets/js/jquery-ui.custom.min.js"></script>
		<script src="${rc.contextPath}/assets/js/jquery.ui.touch-punch.min.js"></script>
		<script src="${rc.contextPath}/assets/js/bootbox.min.js"></script>
		<script src="${rc.contextPath}/assets/js/jquery.gritter.min.js"></script>
		<script src="${rc.contextPath}/assets/js/spin.min.js"></script>
		<!-- ace scripts -->
		<script src="${rc.contextPath}/assets/js/ace-elements.min.js"></script>
		<script src="${rc.contextPath}/assets/js/ace.min.js"></script>
		<!-- validator scripts -->
		<script src="${rc.contextPath}/assets/js/bootstrapValidator.min.js"></script>
		<!-- user scripts -->
		<script src="${rc.contextPath}/assets/js/user/base.js"></script>

		<script type="text/javascript">
			var message = "${message}";
			if(!isEmpty(message)) {
				showMsg(message);
			}

			function showimage(source){
				$("#ShowImage_Form").find("#img_show").html("<image src='"+source+"' class='carousel-inner img-responsive img-rounded' />");
				$("#ShowImage_Form").modal();
			}

			$("#ShowImage_Form").click(function(){
				$("#ShowImage_Form").modal('hide');
			})

			var updateCode = function(obj){
				$("#isAdd").attr("disabled",false);
				$("#isAdd").attr("readOnly",false);
				var codeId = $(obj).attr("value");
				$.ajax({
					url : '${rc.contextPath}/statisticCode/edit',
					type : "POST",
					data : {
						codeId:codeId
					},
					success:function(data) {
						if(data.code == 1) {
							$("#update").click();
							statisticCodeData = data.statisticCode;
							parentCodeData = data.parentCode;
							showIsAdd = data.showIsAdd;
							if (parentCodeData != null){
								$("#parent").attr("value",parentCodeData.id);
								$("#parentText").attr("value",parentCodeData.name);
							} else{
								$("#parent").attr("value",null);
								$("#parentText").attr("value","无");
							}
							$("#id").attr("value",statisticCodeData.id);
							$("#name").attr("value",statisticCodeData.name);
							$("#nameBak").attr("value",statisticCodeData.name);
							$("#enName").attr("value",statisticCodeData.enName);
							$("#code").attr("value",statisticCodeData.code);
							var options = $("#isAdd").find("option");
							var isAdd = statisticCodeData.isAdd;
							for(var i=0; i<options.length; i++){  
							    if(options.eq(i).val() == isAdd){ 
							        options.eq(i).attr("selected", true);  
							    }else{
							    	options.eq(i).attr("selected", false); 
							    }
							} 
							if(showIsAdd){
								$("#isAdd").attr("disabled",true);
								$("#isAdd").attr("readOnly",true);
							}
						} else {
							if(data.msg == undefined){
								showMsg("权限不足！");
							}else{
								showMsg(data.msg);
							}
						}
					},
					error:function(data) {
					}
				});
			}	
		
			jQuery(function($) {
				$("#save").click(function(){
					var id = $("#id").val();
					var parentId = $("#parent").val();
					var name = $("#name").val();
					var nameBak = $("#nameBak").val();
					var isNew = true;
					if (name == nameBak){
						isNew = false;
					}
					var enName = $("#enName").val();
					var code = $("#code").val();
					var isAdd = $("#isAdd").val();
					if(isEmpty(name)) {
						$("#name").focus();
						showMsg("中文名称不能为空！");
					} else if(isEmpty(enName)){
						$("#enName").focus();
						showMsg("名称拼音不能为空！");
					} else{
						$('#myModal').modal('hide');
						$.ajax({
							url : '${rc.contextPath}/statisticCode/save',
							type : "POST",
							data : {
								id : id,
								parentId : parentId,
								name : name,
								enName : enName,
								code : code,
								isAdd : isAdd,
								isNew : isNew,
								nameBak : nameBak
							},
							success:function(data) {
								if(data.code == 1) {
									$("#searchForm").attr("action","${rc.contextPath}/statisticCode/list?message="+data.msg);
									$("#searchForm").submit();
								}
							},
							error:function(data) {
							}
						});
					}
				});
			});

		</script>
	</body>
</html>